
package com.tsystems.school.jabber.server.workers;

import com.tsystems.school.jabber.Message;
import com.tsystems.school.jabber.MessageType;
import com.tsystems.school.jabber.server.ConnectedUser;


public class WorkerFactory implements Worker{
  private ConnectedUser user;
  private Message msg;
  
  public WorkerFactory(Message msg){
    this.msg = msg;
  }
  
  public WorkerFactory(Message msg, ConnectedUser user){
    this.msg = msg;
  }
  
  @Override
  public void run() {
    // TODO Auto-generated method stub
    if (user != null)
      user.getWriteMessagePool().put(work(msg));
    else 
      work(msg);
    
  }

  @Override
  public Message work(Message msg) {
    Message out = null;
    if (msg.getType() == MessageType.LOGIN){
      
    }
    
    if (msg.getType() == MessageType.MESSAGE){
      MESSAGEWorker w = new MESSAGEWorker(msg);
      out = w.work(msg);
    }
    
      
    // TODO Auto-generated method stub
    return out;
  }  
  
  public Message work() {
    return this.work(this.msg);
  }
}
